import { Body, Controller, Get, Post } from '@nestjs/common';
import { ApiOperation, ApiResponse } from '@nestjs/swagger';
import {
  AuthForgetReqDto,
  AuthForgetResDto,
  AuthLoginReqDto,
  AuthLoginResDto,
  AuthQuickReqDto,
  AuthQuickResDto,
  AuthRegReqDto,
  AuthRegResDto,
  AuthWechatReqDto,
  AuthWechatResDto,
  FavoriteAddReqDto,
} from './weapp.dtos';
import { WechatService } from 'src/kits/services/wechat.service';
import { WepayService } from 'src/kits/services/wepay.service';
import { WeappService } from './weapp.service';
import { AuthService } from 'src/auth/auth.service';

@Controller()
export class WeappController {
  constructor(
    private readonly weappService: WeappService,
    private readonly wechatService: WechatService,
    private readonly wepayService: WepayService,
    private readonly authService: AuthService,
  ) {}

  @Post('/auth/login')
  @ApiOperation({
    summary: '账号登录',
    description: '账号密码登录',
    tags: ['auth'],
  })
  @ApiResponse({
    status: 201,
    description: '密码重置成功.',
    type: AuthLoginResDto,
  })
  login(@Body() data: AuthLoginReqDto): AuthLoginResDto {
    console.log(data);
    return {
      token: '账号登录结果',
    };
  }

  @Post('/auth/quick')
  @ApiOperation({
    summary: '短信验证码快捷登录',
    description: '验证码快捷登录',
    tags: ['auth'],
  })
  @ApiResponse({
    status: 201,
    description: '密码重置成功.',
    type: AuthQuickResDto,
  })
  quick(@Body() data: AuthQuickReqDto): AuthQuickResDto {
    console.log(data);
    return {
      token: '快捷登录结果',
    };
  }

  @Post('/auth/wechat')
  @ApiOperation({
    summary: '微信小程序授权',
    description: '微信小程序登录',
    tags: ['auth'],
  })
  @ApiResponse({
    status: 201,
    description: '密码重置成功.',
    type: AuthWechatResDto,
  })
  async wechat(@Body() data: AuthWechatReqDto): AuthWechatResDto {
    const { code } = data;
    const res = await this.wechatService.code2Session(code);
    console.log(res);
    console.log(data);
    const token = this.jwtService.sign({
      id: 1,
    });
    return {
      token: '微信登录结果',
    };
  }

  @Post('/auth/reg')
  @ApiOperation({
    summary: '手机号注册',
    description: '使用手机号码注册账号',
    tags: ['auth'],
  })
  @ApiResponse({
    status: 201,
    description: '密码重置成功.',
    type: AuthRegResDto,
  })
  reg(@Body() data: AuthRegReqDto): AuthRegResDto {
    console.log(data);
    return {
      token: '注册成功直接登录',
    };
  }

  @Post('/auth/forget')
  @ApiOperation({
    summary: '忘记密码',
    description: '验证手机号并重置密码',
    tags: ['auth'],
  })
  @ApiResponse({
    status: 201,
    description: '密码重置成功.',
    type: AuthForgetResDto,
  })
  forget(@Body() data: AuthForgetReqDto): AuthForgetResDto {
    console.log(data);
    return {
      token: '这里需要斟酌忘记密码修改成功后是否需要转为已登录',
    };
  }

  @Post('/favorite')
  @ApiOperation({
    summary: '加入收藏',
    description: '将`商品`,`媒体`加入收藏',
  })
  addFavorite(@Body() data: FavoriteAddReqDto) {
    return this.weappSer;
  }

  @Get('/orders')
  @ApiOperation({
    summary: '订单列表',
    description: '获取当前登录用户的所有订单,支持分页及状态查询',
    tags: ['orders'],
  })
  getOrders() {}
}
